package com.heima.controller;

import com.heima.dto.WmMaterialDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.entity.WmMaterial;
import com.heima.service.WmMaterialService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * 自媒体素材表(WmMaterial)表控制层
 *
 * @author makejava
 * @since 2022-04-10 16:38:33
 */
@RestController
@RequestMapping("/api/v1/material/")
@Api(value = "自媒体素材管理API",tags = "自媒体素材管理")
public class WmMaterialController {
    /**
     * 服务对象
     */
    @Resource
    private WmMaterialService wmMaterialService;

    /**
     * 上传素材
     *
     * @param multipartFile
     * @return
     */
    @PostMapping("/upload_picture")
    public ResponseResult uploadPic(MultipartFile multipartFile) throws IOException {
        return wmMaterialService.uploadPic(multipartFile);
    }
    /**
     * 分页查询素材列表
     *
     * @param dto
     * @return
     */
    @PostMapping("list")
        public ResponseResult list(@RequestBody WmMaterialDto dto)  {
          return wmMaterialService.list(dto);
        }
    /**
     * 删除素材
     *
     * @param id
     * @return
     */
    @GetMapping( "/del_picture/{id}")
    @ApiOperation(value = "素材删除")
    public ResponseResult delete(@PathVariable("id") Long id) {
        wmMaterialService.deleteById(id);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    /**
     * 收藏素材
     *
     * @param id
     * @return
     */
    @GetMapping(path = "/collect/{id}")
    @ApiOperation(value = "素材收藏")
    public ResponseResult collect(@PathVariable("id") Long id) {
        return wmMaterialService.collect(id);
    }

    /**
     * 取消收藏素材
     *
     * @param id
     * @return
     */
    @GetMapping(path = "/cancel_collect/{id}")
    @ApiOperation(value = "素材取消收藏")
    public ResponseResult cancel(@PathVariable("id") Long id) {
        return wmMaterialService.cancel(id);
    }
}




